<style src="./index.scss" lang="scss" scoped rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base],
        computed: {},
        data() {
            return {
                item: null,
                type: 0,
                title: "",
                form: {
                    // 快递公司ID
                    companyId: null,
                    // 快递单号	
                    deliveryNo: "",
                    // 是否需要发货方式 0否 1是
                    isNeedLogistics: 0
                },
                // 窗口显示
                boxVisible: false,
                // 物流列表
                logisticsOptions: [],
            };
        },
        methods: {
            // 验证 
            validate() {
                return new Promise((resolve, reject) => {
                    this.$refs["editForm"].validate((valid) => {
                        valid ? resolve(true) : resolve(false)
                    });
                });
            },
            // 提交
            async submit() {
                if (!await this.validate()) {
                    return
                }

                let _url = "";
                // 发货
                if (this.type == 0) {
                    _url = "mall-site-portal/order/deliveryOrder"
                }
                // 修改快递信息
                else if (this.type == 1) {
                    _url = "mall-site-portal/order/modifyDelivery"
                }
                let _data = await this.$vFN.Http.post({
                    domain: "APP_MAIN_DOMAIN",
                    url: _url,

                    data: {
                        companyId: this.form.companyId,
                        deliveryNo: this.form.deliveryNo,
                        isNeedLogistics: this.form.isNeedLogistics,
                        orderId: this.item.id
                    },
                },window);
                if (_data._ok) {
                    this.$vFN.Tools.messageSuccess("操作成功");
                    this.editBoxClose();
                    this.onSuccess();
                }
            },
            // 成功回调
            onSuccess() {},
            // 取消回调
            onCancel() {},
            // 失败回调
            onError() {},
            // 关闭窗口
            editBoxClose() {
                this.boxVisible = false;
            },
            // 取消
            editBoxCancel() {
                this.editBoxClose();
            },

            show(e, item) {
                console.log(e, item);
            }
        },
        watch: {},
        async mounted() {

            if (this.type == 0) {
                this.title = "发货"
            } else if (this.type == 1) {
                this.title = "修改快递"
            }
            // 数据源 物流列表 this.$vFN.Tools.getSelectListSource
            this.logisticsOptions = await this.$vFN.Http.post({
                domain: "APP_MAIN_DOMAIN",
                url: "mall-site-portal/order/getLogisticsCompany",
                format: false,
            },window);
            this.boxVisible = true;

        },
        beforeCreate() {},
    };
</script>